var Mock = require('mockjs')

// const getParams = (url, name) => {
//   const index = url.indexOf('?')
//   if (index !== -1) {
//     const newArr = url.substring(index + 1).split('&')
//     for (var i = 0; i < newArr.length; i++) {
//       const itemArr = newArr[i].split('=')
//       if (itemArr[0] === name) {
//         return itemArr[1]
//       }
//     }
//   }
//   return null
// }

// 登录接口
Mock.mock('/mock/login', 'get', require('../mock/data/loginSuccess.json'))
// 获取菜单接口
Mock.mock('/mock/menus', 'get', require('../mock/data/menuSuccess.json'))
// 获取角色列表接口
Mock.mock('/mock/getRolesList', 'get', require('../mock/data/getRolesList.json'))
// 获取权限列表接口
Mock.mock('/mock/getAllrightsDict', 'get', require('../mock/data/getAllrightsDict.json'))
// 获取所有角色
Mock.mock('/mock/getALlRole', 'get', require('../mock/data/getALlRole.json'))
// 获取权限列表接口
Mock.mock('/mock/getRightsList', 'get', require('../mock/data/getRightsList.json'))
// 获取用户列表接口
Mock.mock('/mock/getUserList', 'post', (options) => {
  let { pagenum, pagesize } = JSON.parse(options.body)
  // 初始化
  if (!pagesize || !pagenum) {
    pagenum = 1
    pagesize = 6
  }
  if (pagenum === 1 && pagesize <= 6) {
    return require('../mock/data/getUserList_1.json')
  } else if (pagenum > 1 && pagesize <= 6) {
    return require('../mock/data/getUserList_2.json')
  } else {
    return require('../mock/data/getUserList_3.json')
  }
})
